package com.tangruojie.controller;

import com.tangruojie.domain.LoginUser;
import com.tangruojie.domain.ResponseCode;
import com.tangruojie.domain.ResponseResult;
import com.tangruojie.service.LoginService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
@RequiredArgsConstructor
public class LoginController {

    private final LoginService loginService;

    @PostMapping("/user")
    public ResponseResult login(@RequestBody LoginUser loginUser) {
        Map<String, String> result = loginService.login(loginUser);
        return new ResponseResult(
                result != null ? ResponseCode.LOGIN_SUCCESS : ResponseCode.LOGIN_ERROR,
                result != null ? "登录成功" : "登录失败",
                result
        );
    }

}
